import React, { FC, useEffect } from "react";
import { QuestParagraphPropsType } from "./interface";
import { Form, Input, Checkbox } from "antd";
const { TextArea } = Input;
const PropComponent: FC<QuestParagraphPropsType> = (props: QuestParagraphPropsType) => {
  const { text, isCenter, onChange, disabled } = props;

  const [form] = Form.useForm();
  useEffect(() => {
    form.setFieldsValue({ text, isCenter });
  }, [text, isCenter]);
  function handleValueChange() {
    if (onChange) {
      onChange(form.getFieldsValue());
    }
  }

  return (
    <Form
      form={form}
      layout="vertical"
      onChange={handleValueChange}
      initialValues={{ text, isCenter }}
      disabled={disabled}>
      <Form.Item
        label="段落内容"
        name="text"
        rules={[{ required: true, message: "请输入段落内容" }]}>
        <TextArea></TextArea>
      </Form.Item>
      <Form.Item name="isCenter" valuePropName="checked">
        <Checkbox>居中显示</Checkbox>
      </Form.Item>
    </Form>
  );
};
export default PropComponent;
